package com.brucekong.slm.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
// 返回对象
@ResponseBody
@Slf4j
@SuppressWarnings("unchecked")
public class ErrorException {
    @ExceptionHandler(Exception.class)
    public Result errorException(HttpServletRequest request, Exception e) throws Exception {
        Result result = new Result();
        result.setCode(1);
        result.setMsg(e.getMessage());
        result.setSuccess(false);
        result.setData(request.getRequestURL());
        return result;
    }
}
